import { MyVue } from 'src/wl/my_vue';
import Vue from 'vue';
import { Component, Emit, Prop, Provide, Watch } from 'vue-property-decorator'
import { WebManageConst } from "src/consts/web_manage_const";
@Component({})
export default class WebMAccPanel extends MyVue {
    name: string = 'WebMAccPanel';
    formData: any;
    footerFlag: boolean = true;
    title: String;
    titleIcon: String;

    beforeCreate(): void {
    }

    initData(that?: any): void {
        var index = WLStore().state.webMShow.acc_index
        var type = WLStore().state.webMShow.login_key
        if (WLStore().state.webMShow.acc_type == "edit") {
            that.title = "公共账号信息详情"
            that.titleIcon = "btn_xq"
            that.formData = WLStore().state.webMShow[type + 'Accounts'][index];
        } else if (WLStore().state.webMShow.acc_type == "add") {
            that.title = "新增公共账号信息"
            that.titleIcon = "pop_xz"
            that.formData = {}
            that.formData.shi = "shi"
        }
    }

    mounted(): void {
    }

    editAcc(): void {
        this.$refs.webMAccForm.validate((valid: Boolean) => {
            if (valid) {
                var sendData = this.formData
                if (sendData.shi == "shi") {
                    sendData.flag = true
                } else if (sendData.shi == "fou") {
                    sendData.flag = false
                }
                WLCommit(WebManageConst.CommitAccData, sendData)
            } else {
                WLMessage("必填字段为空,无法保存公共账号信息", "warning")
                return false;
            }
        })
    }

    continueAcc(): void {
        this.$refs.webMAccForm.validate((valid: Boolean) => {
            if (valid) {
                var sendData = JSON.parse(JSON.stringify(this.formData))
                sendData.isContinue = true
                if (sendData.shi == "shi") {
                    sendData.flag = true
                } else if (sendData.shi == "fou") {
                    sendData.flag = false
                }
                WLCommit(WebManageConst.CommitAccData, sendData)

                setTimeout(() => {
                    this.$refs.webMAccForm.resetFields();
                }, 500);
            } else {
                WLMessage("必填字段为空,无法保存公共账号信息", "warning")
                return false;
            }
        })
    }
}